/*
 * Bismillahirrahmanirrahim...
 * Software ini bebas untuk anda gunakan dan kembangkan
 * Segala resiko akibat penggunaan software ini ditanggung sendiri ya...
 * Semoga bermanfaat, Amin...
 */

package KomponenGUI;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
 *
 * @author farazinux
 */
public class TextBox extends JTextField {

    public TextBox() {
        setOpaque(false);
        setBorder(new EmptyBorder(5, 5, 5, 5));

        addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(FocusEvent e) {
                setKlik(true);
            }

            @Override
            public void focusLost(FocusEvent e) {
                setKlik(false);
            }


        });
    }


    private Paint paint;
    private Paint glass;
    private Shape shape;
    private boolean klik;

    public boolean isKlik() {
        return klik;
    }

    public void setKlik(boolean klik) {
        this.klik = klik;
        repaint();
    }



    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D gd = (Graphics2D) g.create();
        shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), getHeight(), getHeight());

        if(isKlik()){
            glass = new GradientPaint(0, 0, new Color(1F, 1F, 1F, 0F), 0, getHeight(), new Color(1F, 1F, 1F, 0.5F));
            paint = new GradientPaint(0, 0, new Color(getBackground().getRed(), getBackground().getGreen(), getBackground().getBlue()), getWidth(), 0,Color.BLACK );
        }else{
            glass = new GradientPaint(0, 0, new Color(1F, 1F, 1F, 0.5F), 0, getHeight(), new Color(1F, 1F, 1F, 0F));
            paint = new GradientPaint(0, 0, Color.BLACK, getWidth(), 0, new Color(getBackground().getRed(), getBackground().getGreen(), getBackground().getBlue()));
        }
        gd.setPaint(paint);
        gd.fill(shape);

        gd.setPaint(glass);
        gd.fill(shape);
        
        gd.dispose();
        super.paintComponent(g);

    }



}
